import { Controller, Get, Request, Post, Delete, Put, Query, UseGuards, UseInterceptors, Body, UploadedFiles } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { FileFieldsInterceptor } from '@nestjs/platform-express';
import { ProductService } from './product.service';


@Controller('product')
export class ProductController {
    constructor(
        private readonly productService: ProductService
    ) { }
    // @UseGuards(AuthGuard('jwt'))
    @Post('add')
    @UseInterceptors(FileFieldsInterceptor([
        { name: 'thumbnail', maxCount: 1 },
        { name: 'product', maxCount: 99 }
    ]))
    add(@UploadedFiles() files: any, @Body() body: any) {
        return this.productService.add(files, body);
    }
    // @UseGuards(AuthGuard('jwt'))
    @Delete('delete')
    delete(@Request() req: any) {
        return this.productService.delete(req.body.id);
    }
    // @UseGuards(AuthGuard('jwt'))
    @Put('update')
    @UseInterceptors(FileFieldsInterceptor([
        { name: 'thumbnail', maxCount: 1 },
        { name: 'product', maxCount: 99 }
    ]))
    update(@UploadedFiles() files, @Body() body: any) {
        return this.productService.update(files, body);
    }

    @Get()
    index(@Query() query: any) {
        return this.productService.findAll(query);
    }

    @Get('getProductsByCategory')
    getProductsByCategory(@Query() query: any) {
        const { subject, series, product_type } = query
        return this.productService.getProductsByCategory(subject, series, product_type);
    }

    @Get('getProductById')
    getProductById(@Query() query: any) {
        return this.productService.getProductById(query.id);
    }

    // @Get('getProductsByType')
    // getProductsByType(@Query() query: any) {
    //     const { product_type, subject, series } = query
    //     return this.productService.getProductsByType(product_type, subject, series);
    // }
}
